Skip to content

Conversation

@lemorage
Copy link

@lemorage lemorage commented Jan 14, 2026

Which issue does this PR close?

Rationale for this change

The epoch function incorrectly used date_part(array, DatePart::Second) for intervals which only extracts the seconds component of the interval structure (0 for "15 minutes"), not the total seconds from all components.

What changes are included in this PR?

  • Modified epoch() function in date_part.rs to properly handle interval types by extracting struct fields and calculating total seconds
  • Added regression tests in date_part.slt

Are these changes tested?

Yes. Added tests verifying correct conversion for all interval types and precision levels.

Are there any user-facing changes?

Yes. extract(epoch from interval) now returns correct total seconds instead of 0.

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions Changes to functions implementation labels Jan 14, 2026
Copy link
Contributor

@Jefffrey Jefffrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Results seem consistent with DuckDB 👍


fn epoch(array: &dyn Array) -> Result<ArrayRef> {
const SECONDS_IN_A_DAY: f64 = 86400_f64;
const DAYS_PER_MONTH: f64 = 30_f64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose there's no easier way to define this for intervals 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I just followed the PostgreSQL-way for simplicity here, what do u think?

https://doxygen.postgresql.org/datatype_2timestamp_8h.html#ad35c6d425de4ccc4718c6ce7f4bfbba2

Copy link
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing! Maybe we could add some more test cases? E.g. extract(epoch from arrow_cast( '100ms'::interval, 'Interval::(MothDayNano)') -> 0.1` and such.

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation functions Changes to functions implementation sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

select extract(epoch from ('15 minutes')::interval) gives wrong result

4 participants